<script setup lang="ts">
import SeamlessScroll from "@/components/seamless-scroll";
import { computed, onMounted, reactive } from "vue";
import { useSettingStore } from "@/stores";
import { storeToRefs } from "pinia";
import EmptyCom from "@/components/empty-com";
import { ElMessage } from "element-plus";

const settingStore = useSettingStore();
const { defaultOption, indexConfig } = storeToRefs(settingStore);

// 告警数据（根据用户提供的格式）
const alarmData = [
  {
    deviceId: "12541",
    alarmLevel: "次要",
    address: "上海数据港 / 鹏博士电层1",
    time: "2025-09-15 00:28:13",
    location: "0-subrack-5-U5N402-2(IN2/OUT2(54波TDT南昌-长沙至夏龙）)-OCH:1"
  },
  {
    deviceId: "12542",
    alarmLevel: "主要",
    address: "上海GDS / 上海GDS-M24",
    time: "2025-09-24 21:40:04",
    location: "0-subrack-5-U5N402-2(IN2/OUT2(54波TDT南昌-长沙至夏龙）)-OCH:1"
  },
  {
    deviceId: "12543",
    alarmLevel: "重要",
    address: "字节跳动机房",
    time: "2025-09-24 21:38:03",
    location: "0-subrack-11-Z8NS4-1(IN/OUT)-OCH:1"
  },
  {
    deviceId: "12544",
    alarmLevel: "次要",
    address: "广州 / 萝岗电层1",
    time: "2025-09-24 21:39:39",
    location: "0-subrack-9-S2N502-2(IN2/OUT2同安37波)-OCh:1-ODUCn:1-ODU4:2"
  },
  {
    deviceId: "12545",
    alarmLevel: "主要",
    address: "宝信腾讯 / 宝信M24",
    time: "2025-09-24 21:39:39",
    location: "0-subrack-3-U6N402-1(IN1/OUT1)-OCH:1"
  },
  {
    deviceId: "12546",
    alarmLevel: "次要",
    address: "上海数据港 / 鹏博士电层2",
    time: "2025-09-24 21:39:14",
    location: "0-subrack-3-S7N502-2(IN2/OUT2南昌193.15)-OCH:1"
  },
  {
    deviceId: "12547",
    alarmLevel: "主要",
    address: "4704松江",
    time: "2025-09-24 21:37:12",
    location: "0-subrack-15-13FIU-1(IN/OUT)-OTS:1"
  },
  {
    deviceId: "12548",
    alarmLevel: "重要",
    address: "9-19泉州U32",
    time: "2025-09-24 21:37:31",
    location: "-"
  }
];

const state = reactive<any>({
  list: alarmData,
  defaultOption: {
    ...defaultOption.value,
    singleHeight: 252,
    limitScrollNum: 3,
  },
  scroll: true,
});

const getLevelClass = (level: string) => {
  switch (level) {
    case "重要":
      return "level-critical";
    case "主要":
      return "level-major";
    case "次要":
      return "level-minor";
    default:
      return "level-info";
  }
};

const comName = computed(() => {
  if (indexConfig.value.rightBottomSwiper) {
    return SeamlessScroll;
  } else {
    return EmptyCom;
  }
});

onMounted(() => {
  // 数据已加载完成
});
</script>

<template>
  <div class="right_bottom_wrap beautify-scroll-def" :class="{ 'overflow-y-auto': !indexConfig.rightBottomSwiper }">
    <component
      :is="comName"
      :list="state.list"
      v-model="state.scroll"
      :singleHeight="state.defaultOption.singleHeight"
      :step="state.defaultOption.step"
      :limitScrollNum="state.defaultOption.limitScrollNum"
      :hover="state.defaultOption.hover"
      :singleWaitTime="state.defaultOption.singleWaitTime"
      :wheel="state.defaultOption.wheel"
    >
      <ul class="right_bottom">
        <li class="right_center_item" v-for="(item, i) in state.list" :key="i">
          <span class="orderNum">{{ i + 1 }}</span>
          <div class="inner_right">
            <div class="dibu"></div>
            <div class="flex">
              <div class="info">
                <span class="labels">设备ID：</span>
                <span class="text-content zhuyao">{{ item.deviceId }}</span>
              </div>
              <div class="info">
                <span class="labels">告警级别：</span>
                <span class="text-content" :class="getLevelClass(item.alarmLevel)">
                  {{ item.alarmLevel }}
                </span>
              </div>
            </div>
            
            <div class="flex">
              <div class="info">
                <span class="labels">地址：</span>
                <span class="text-content ciyao">{{ item.address }}</span>
              </div>
            </div>
            
            <div class="flex">
              <div class="info">
                <span class="labels">时间：</span>
                <span class="text-content">{{ item.time }}</span>
              </div>
            </div>
            
            <div class="flex">
              <div class="info">
                <span class="labels">告警定位：</span>
                <span class="text-content ciyao" :title="item.location">
                  {{ item.location }}
                </span>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </component>
  </div>
</template>

<style scoped lang="scss">
.right_bottom {
  width: 100%;
  height: 100%;

  .right_center_item {
    display: flex;
    align-items: center;
    justify-content: center;
    height: auto;
    padding: 10px;
    font-size: 14px;
    color: #fff;

    .orderNum {
      margin: 0 20px 0 -20px;
    }

    .inner_right {
      position: relative;
      height: 100%;
      width: 400px;
      flex-shrink: 0;
      line-height: 1.5;

      .dibu {
        position: absolute;
        height: 2px;
        width: 104%;
        background-image: url("@/assets/img/zuo_xuxian.png");
        bottom: -12px;
        left: -2%;
        background-size: cover;
      }
    }

    .info {
      margin-right: 10px;
      display: flex;
      align-items: center;

      .labels {
        flex-shrink: 0;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
      }

      .zhuyao {
        color: $primary-color;
        font-size: 15px;
      }

      .ciyao {
        color: rgba(255, 255, 255, 0.8);
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .level-critical {
        color: #ff4d4f;
        font-weight: bold;
      }

      .level-major {
        color: #faad14;
        font-weight: bold;
      }

      .level-minor {
        color: #52c41a;
        font-weight: bold;
      }
    }
  }
}

.right_bottom_wrap {
  overflow: hidden;
  width: 100%;
  height: 252px;
}

.overflow-y-auto {
  overflow-y: auto;
}
</style>
